package huxibianjie.com.lbscandroid.manager;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import huxibianjie.com.lbscandroid.R;
import huxibianjie.com.lbscandroid.ui.new_activity.CompleteCipherActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.ForgetPasswordActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.LoginActivity;
import huxibianjie.com.lbscandroid.ui.old.RankingsActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.RegisterActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.AccountDetailsActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.CampaignActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.EnergyRuleActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.ExplainActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.HomeActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.InviteFriendActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.InviteRecordActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.MyPageActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.TaskCommunityActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.TaskFollowActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.UpdateWalletAddressActivity;
import huxibianjie.com.lbscandroid.ui.new_activity.WithdrawActivity;


/**
 * 页面跳转
 * Created by CZF on 2018/7/24.
 */
public class RouteManager {


    private static class Holder {
        private static RouteManager routeManager = new RouteManager();
    }

    private RouteManager() {
    }

    public static RouteManager getInstance() {
        return Holder.routeManager;
    }

    private void startActivity(Context context, Class<?> cls) {
        startActivity(context, cls, -1, null, -1);
    }

    private void startActivity(Context context, Class<?> cls, int flags) {
        startActivity(context, cls, -1, null, flags);
    }

    private void startActivity(Context context, Class<?> cls, Bundle data) {
        startActivity(context, cls, -1, data, -1);
    }

    private void startActivity(Context context, Class<?> cls, int requestCode, Bundle data) {
        startActivity(context, cls, requestCode, data, -1);
    }

    private void startActivity(Context context, Class<?> cls, Bundle data, int flags) {
        startActivity(context, cls, -1, data, flags);
    }

    private void startActivity(Context context, Class<?> cls, int requestCode, Bundle data, int flags) {
        if (context == null) {
            return;
        }
        Intent intent = new Intent(context, cls);
        if (data != null) {
            intent.putExtras(data);
        }
        if (flags != -1) {
            intent.addFlags(flags);
        }
        if (context instanceof Activity) {
            if (requestCode == 0) {
                context.startActivity(intent);
            } else {
                ((Activity) context).startActivityForResult(intent, requestCode);
            }
            ((Activity) context).overridePendingTransition(R.anim.slide_open_in_right, 0);
        } else {
            context.startActivity(intent);
        }
    }


    /**
     * 我的信息界面
     *
     * @param activity
     */
    public void showMainActivity(Activity activity) {
        startActivity(activity, HomeActivity.class);
    }

    /**
     * 跳转关注订阅号页面
     *
     * @param activity
     */
    public void showFollowActivity(Activity activity) {
        startActivity(activity, TaskFollowActivity.class);
    }

    /**
     * 跳转关注社区页面
     *
     * @param activity
     */
    public void showCommunityTask(Activity activity) {
        startActivity(activity, TaskCommunityActivity.class);
    }

    /**
     * 邀请好友
     *
     * @param activity
     */
    public void showInviteFriendActivity(Activity activity) {
        startActivity(activity, InviteFriendActivity.class);
    }


    /**
     * 跳转注册页面
     */
    public void showRegisterActivity(Activity activity) {
        startActivity(activity, RegisterActivity.class);
    }

    //跳转登陆页面
    public void showLoginActivity(Activity activity) {
        startActivity(activity, LoginActivity.class);
    }

    //邀请注册页面
    public void showRankings(Activity activity) {
        startActivity(activity, RankingsActivity.class);
    }

    //忘记密码页面
    public void showForgetPasswordActivity(Activity activity) {
        startActivity(activity, ForgetPasswordActivity.class);
    }

    //补全密码
    public void showCompleteCipherActivity(Activity activity, String phone) {
        Bundle bundle = new Bundle();
        bundle.putString("phone", phone);
        startActivity(activity, CompleteCipherActivity.class, bundle);
    }

    //我的界面
    public void showCampaignActivity(Activity activity) {
        startActivity(activity, CampaignActivity.class);
    }

    //活动界面
    public void showMyPageActivity(Activity activity) {
        startActivity(activity, MyPageActivity.class);
    }

    /**
     * 双倍能量介绍
     */
    public void showEnergyRuleActivity(Activity activity) {
        startActivity(activity, EnergyRuleActivity.class);
    }

    /**
     * 邀请记录
     */
    public void showInviteRecordActivity(Activity activity) {
        startActivity(activity, InviteRecordActivity.class);
    }

    /**
     * 账户明细
     */
    public void showAccountDetailsActivity(Activity activity) {
        startActivity(activity, AccountDetailsActivity.class);
    }

    /**
     * 货币提现
     */
    public void showWithdrawActivity(Activity activity) {
        startActivity(activity, WithdrawActivity.class);
    }

    /**
     * 钱包地址更换/绑定
     */
    public void showUpdateWalletAddressActivity(Activity activity) {
        startActivity(activity, UpdateWalletAddressActivity.class);
    }

    /**
     * 说明
     */
    public void showExplainActivity(Activity activity) {
        startActivity(activity, ExplainActivity.class);
    }

}